<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"          			
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      >
    <ui:composition template="TaskProLayout.xhtml">
        <ui:define name="content">
            <div class="Post">
                <h:form id="templateEditForm">   
                    <p:dataTable var="task" value="#{taskBean.kantorTemplates}" selectionMode="single"
                                 selection="#{taskBean.newTemplate}" rowKey="#{task.id}" paginator="true"
                                 paginatorAlwaysVisible="false" rows="15">  
                        <f:facet name="header" >
                            <h:outputText value="Template to edit" />
                        </f:facet>
                        <p:ajax event="rowSelect"  
                                update=":createTaskForm,:assignmentFile"  listener="#{taskBean.chooseNewTask()}"/>   

                        <p:column headerText="Label">   
                            <h:outputText value="#{task.name}" />
                        </p:column>  
                        <p:column headerText="Description">   
                            <h:outputText value="#{task.description}" >
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column>  
                        <p:column headerText="Date of creation">   
                            <h:outputText value="#{task.dateOfCreation}" >
                                 <f:convertDateTime type="both" timeZone="Europe/Prague"></f:convertDateTime>
                            </h:outputText>
                        </p:column>  
                        <f:facet name="footer">
                            <h:outputText value=" " />
                        </f:facet>
                    </p:dataTable>  

                </h:form>
            </div>
            <div class="Post">
                <h2><h:outputText value="Selected template to modify"/></h2>
                <h:form id="createTaskForm">

                    <h:panelGrid columns="2">
                        <h:outputText value="Task name"/>
                        <p:inputText id="taskName" required="true" style="width: 300px" value="#{taskBean.newTemplate.name}" />
                        <h:outputText value="Task description"/>
                        <p:inputTextarea id="taskDescr" style="height: 100px;width: 300px" required="true" cols="20" rows="5" maxlength="255" value="#{taskBean.newTemplate.description}"/>
                        <h:outputText value=""/>

                    </h:panelGrid>       
                    <p:commandButton style="" value="Modify task" action="#{taskBean.modifyTask()}" styleClass="gridCenter" ajax="false"></p:commandButton>
                    <p:commandButton style="" value="Remove task" action="#{taskBean.removeTask()}" styleClass="gridCenter" ajax="false"></p:commandButton>
                </h:form>  
            </div>
            <div class="Post">
                <h:form id="assignmentFile">
                    <p:dataTable id="assignmentFileTable" value="#{taskBean.filesWithTemplate}" var="tasks" rowKey="#{tasks.id}">
                        <f:facet name="header" >
                            <h:outputText value="Files with template" />
                        </f:facet>
                        <p:column headerText="File name">
                            <h:outputText value="#{tasks.fileName}" >
                                <f:converter converterId="StringConverter" />
                            </h:outputText>
                        </p:column>
                        <p:column headerText="File size">
                            <h:outputText value="#{tasks.fileSize}" />
                        </p:column>
                        <p:column headerText="Action">
                            <p:commandButton value="Download" ajax="false">
                                <p:fileDownload id="koko" value="#{taskBean.download(tasks)}"/>
                            </p:commandButton>
                            <p:commandButton value="Remove" ajax="true"  update=":assignmentFile,:createTaskForm"  actionListener="#{taskBean.removeFile(tasks)}"/>
                        </p:column>
                           <f:facet name="footer">
                            <h:outputText value=" " />
                        </f:facet>
                    </p:dataTable>
                </h:form>
            </div>
            <div class="Post">
                <h:form id="fileUpload" enctype="multipart/form-data" prependId="false">            
                    <h:outputLabel for="Upload" value="Upload file (pdf,zip,java)" />
                    <p:fileUpload  id="Upload"  multiple="true" sizeLimit="16777216" fileUploadListener="#{taskBean.handleFileUpload}" allowTypes="/(\.|\/)(pdf|zip|java)$/"  mode="advanced"  update=":assignmentFile:assignmentFileTable" />                  
                </h:form>  
            </div>
        </ui:define>
    </ui:composition>
</html>